package cn.rc.rcsystem.service.impl;

import cn.rc.rcsystem.domain.LeaseOrderCar;
import cn.rc.rcsystem.exception.GlobalException;
import cn.rc.rcsystem.exception.GlobalExceptionCodeEnum;
import cn.rc.rcsystem.mapper.LeaseOrderCarMapper;
import cn.rc.rcsystem.result.JSONResult;
import cn.rc.rcsystem.service.ILeaseOrderCarService;
import cn.rc.rcsystem.util.AssertUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author director
 * @since 2022-12-09
 */
@Service
public class LeaseOrderCarServiceImpl extends ServiceImpl<LeaseOrderCarMapper, LeaseOrderCar> implements ILeaseOrderCarService {

    @Override
    public JSONResult addLeaseOrderCar(LeaseOrderCar leaseOrderCar) {
        EntityWrapper<LeaseOrderCar> wrapper = new EntityWrapper<>();
        wrapper.eq("sn",leaseOrderCar.getSn());
        LeaseOrderCar leaseOrderCar1 = selectOne(wrapper);
        if(leaseOrderCar1==null){
            insert(leaseOrderCar);
        }
        if(leaseOrderCar1!=null){
            throw new GlobalException( GlobalExceptionCodeEnum.ORDER_ALREADY_EXISTS_ERR0R);
        }

        return JSONResult.success();
    }
}
